import { Command } from '../constant';
import _ from 'lodash';
import { IMainReducer } from '../types';
import { Action } from 'typings';
import produce from 'immer';
import * as immerUtil from '@/redux/immer-util';

const INITIAL_STATE: IMainReducer = {
  isReady: false,
  isLoading: false,
  questionList: [],
  question: [
    {
      "id": 120,
      "investigationId": 24,
      "questionType": 1,
      "questionName": "您是哪栋楼的业主？",
      "questionDescription": null,
      "requiredFlag": null,
      "options": [
        {
          "id": 262,
          "investigationId": 24,
          "questionId": 120,
          "optionName": "1",
          "optionDescription": null,
          "check": false,
          "userCount": null,
          "answers": null
        },
        {
          "id": 263,
          "investigationId": 24,
          "questionId": 120,
          "optionName": "2",
          "optionDescription": null,
          "check": false,
          "userCount": null,
          "answers": null
        },
        {
          "id": 264,
          "investigationId": 24,
          "questionId": 120,
          "optionName": "3",
          "optionDescription": null,
          "check": false,
          "userCount": null,
          "answers": null
        },
        {
          "id": 265,
          "investigationId": 24,
          "questionId": 120,
          "optionName": "4",
          "optionDescription": null,
          "check": false,
          "userCount": null,
          "answers": null
        },
        {
          "id": 266,
          "investigationId": 24,
          "questionId": 120,
          "optionName": "5",
          "optionDescription": null,
          "check": false,
          "userCount": null,
          "answers": null
        },
        {
          "id": 267,
          "investigationId": 24,
          "questionId": 120,
          "optionName": "6",
          "optionDescription": null,
          "check": false,
          "userCount": null,
          "answers": null
        },
        {
          "id": 268,
          "investigationId": 24,
          "questionId": 120,
          "optionName": "7",
          "optionDescription": null,
          "check": false,
          "userCount": null,
          "answers": null
        },
        {
          "id": 269,
          "investigationId": 24,
          "questionId": 120,
          "optionName": "8",
          "optionDescription": null,
          "check": false,
          "userCount": null,
          "answers": null
        }
      ],
      "answerList": [],
      "answers": null,
      "allUserCount": null
    },
    {
      "id": 121,
      "investigationId": 24,
      "questionType": 1,
      "questionName": "您每年在小区居住的时间？",
      "questionDescription": null,
      "requiredFlag": null,
      "options": [
        {
          "id": 270,
          "investigationId": 24,
          "questionId": 121,
          "optionName": "长期居住",
          "optionDescription": null,
          "check": false,
          "userCount": null,
          "answers": null
        },
        {
          "id": 271,
          "investigationId": 24,
          "questionId": 121,
          "optionName": "每年有一半的时间居住",
          "optionDescription": null,
          "check": false,
          "userCount": null,
          "answers": null
        },
        {
          "id": 272,
          "investigationId": 24,
          "questionId": 121,
          "optionName": "本人长期在外，偶尔居住",
          "optionDescription": null,
          "check": false,
          "userCount": null,
          "answers": null
        },
        {
          "id": 273,
          "investigationId": 24,
          "questionId": 121,
          "optionName": "没有居住",
          "optionDescription": null,
          "check": false,
          "userCount": null,
          "answers": null
        }
      ],
      "answerList": [],
      "answers": null,
      "allUserCount": null
    },
    {
      "id": 122,
      "investigationId": 24,
      "questionType": 1,
      "questionName": "您对小区物业保安的安全防范意识是否满意?",
      "questionDescription": null,
      "requiredFlag": null,
      "options": [
        {
          "id": 274,
          "investigationId": 24,
          "questionId": 122,
          "optionName": "非常满意",
          "optionDescription": null,
          "check": false,
          "userCount": null,
          "answers": null
        },
        {
          "id": 275,
          "investigationId": 24,
          "questionId": 122,
          "optionName": "满意",
          "optionDescription": null,
          "check": false,
          "userCount": null,
          "answers": null
        },
        {
          "id": 276,
          "investigationId": 24,
          "questionId": 122,
          "optionName": "一般",
          "optionDescription": null,
          "check": false,
          "userCount": null,
          "answers": null
        },
        {
          "id": 277,
          "investigationId": 24,
          "questionId": 122,
          "optionName": "差",
          "optionDescription": null,
          "check": false,
          "userCount": null,
          "answers": null
        },
        {
          "id": 278,
          "investigationId": 24,
          "questionId": 122,
          "optionName": "非常差",
          "optionDescription": null,
          "check": false,
          "userCount": null,
          "answers": null
        }
      ],
      "answerList": [],
      "answers": null,
      "allUserCount": null
    },
    {
      "id": 123,
      "investigationId": 24,
      "questionType": 1,
      "questionName": "您对小区物业的整体服务质量是否满意?",
      "questionDescription": null,
      "requiredFlag": null,
      "options": [
        {
          "id": 279,
          "investigationId": 24,
          "questionId": 123,
          "optionName": "非常满意",
          "optionDescription": null,
          "check": false,
          "userCount": null,
          "answers": null
        },
        {
          "id": 280,
          "investigationId": 24,
          "questionId": 123,
          "optionName": "满意",
          "optionDescription": null,
          "check": false,
          "userCount": null,
          "answers": null
        },
        {
          "id": 281,
          "investigationId": 24,
          "questionId": 123,
          "optionName": "一般",
          "optionDescription": null,
          "check": false,
          "userCount": null,
          "answers": null
        },
        {
          "id": 282,
          "investigationId": 24,
          "questionId": 123,
          "optionName": "差",
          "optionDescription": null,
          "check": false,
          "userCount": null,
          "answers": null
        },
        {
          "id": 283,
          "investigationId": 24,
          "questionId": 123,
          "optionName": "非常差",
          "optionDescription": null,
          "check": false,
          "userCount": null,
          "answers": null
        }
      ],
      "answerList": [],
      "answers": null,
      "allUserCount": null
    },
    {
      "id": 124,
      "investigationId": 24,
      "questionType": 2,
      "questionName": "您所在小区需要进行改造的地方是？",
      "questionDescription": null,
      "requiredFlag": null,
      "options": [
        {
          "id": 284,
          "investigationId": 24,
          "questionId": 124,
          "optionName": "井盖更换",
          "optionDescription": null,
          "check": false,
          "userCount": null,
          "answers": null
        },
        {
          "id": 285,
          "investigationId": 24,
          "questionId": 124,
          "optionName": "线路规整",
          "optionDescription": null,
          "check": false,
          "userCount": null,
          "answers": null
        },
        {
          "id": 286,
          "investigationId": 24,
          "questionId": 124,
          "optionName": "地砖修缮、更换",
          "optionDescription": null,
          "check": false,
          "userCount": null,
          "answers": null
        },
        {
          "id": 287,
          "investigationId": 24,
          "questionId": 124,
          "optionName": "路面修整",
          "optionDescription": null,
          "check": false,
          "userCount": null,
          "answers": null
        },
        {
          "id": 288,
          "investigationId": 24,
          "questionId": 124,
          "optionName": "内外墙粉刷",
          "optionDescription": null,
          "check": false,
          "userCount": null,
          "answers": null
        },
        {
          "id": 289,
          "investigationId": 24,
          "questionId": 124,
          "optionName": "标识划线",
          "optionDescription": null,
          "check": false,
          "userCount": null,
          "answers": null
        },
        {
          "id": 290,
          "investigationId": 24,
          "questionId": 124,
          "optionName": "绿化改造",
          "optionDescription": null,
          "check": false,
          "userCount": null,
          "answers": null
        }
      ],
      "answerList": [],
      "answers": null,
      "allUserCount": null
    },
    {
      "id": 125,
      "investigationId": 24,
      "questionType": 3,
      "questionName": "对本小区的物业管理，您还有什么问题需要提意见的，请列举出来。",
      "questionDescription": null,
      "requiredFlag": null,
      "options": [],
      "answerList": [],
      "answers": null,
      "allUserCount": null
    }
  ]
};

export default function main(state = INITIAL_STATE, action: Action): IMainReducer {
  const { type, payload } = action;

  return produce<IMainReducer>(state, (draftState) => {
    switch (type) {
      //通用改变数据
      case Command.commonChange:
        return immerUtil.commonChange(draftState, { ...payload, key: 'main' });

      //初始化
      case Command.init:
        draftState.isReady = true;
        for (let propKey in payload.main) {
          //@ts-ignore 这里处理的不够好.
          draftState[propKey] = payload.main[propKey];
        }
        return draftState;

      //重置
      case Command.clean:
        for (let propKey in INITIAL_STATE) {
          //@ts-ignore 这里处理的不够好.
          draftState[propKey] = INITIAL_STATE[propKey];
        }
        return draftState;
    }
  });
}

//create by moon https://github.com/creasy2010/moon
